package com.andy.customerService.service.impl;

import com.andy.customerService.entity.WorkOrder;
import com.andy.customerService.enums.StatusEnum;
import com.andy.customerService.mapper.WorkOrderMapper;
import com.andy.customerService.service.WorkOrderService;
import com.andy.customerService.vo.JsonBaseResult;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 工单表 服务实现类
 * </p>
 *
 * @author Andy
 * @since 2021-12-27
 */
@Service
public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder> implements WorkOrderService {

    @Autowired
    private WorkOrderMapper workOrderMapper;


    @Override
    public JsonBaseResult<Object> addWorkOrder(WorkOrder workOrder) {
        JsonBaseResult<Object> result = new JsonBaseResult<>();
        int count = workOrderMapper.insert(workOrder);
        if (count != 1) {
            result.setResultStatus(StatusEnum.FAILED);
        }
        return result;
    }

    /**
     * 根据id修改工单信息
     * @param workOrder
     */
    @Override
    public JsonBaseResult<Object> editWorkOrderById(WorkOrder workOrder) {
        JsonBaseResult<Object> result = new JsonBaseResult<>();
        int count = workOrderMapper.updateById(workOrder);
        if (count != 1) {
            result.setResultStatus(StatusEnum.FAILED);
        }
        return result;
    }

    /**
     * 根据id删除工单信息
     * @param id
     */
    @Override
    public JsonBaseResult<Object> deleteWorkOrderById(Long id) {
        JsonBaseResult<Object> result = new JsonBaseResult<>();
        int count = workOrderMapper.deleteById(id);
        if (count != 1) {
            result.setResultStatus(StatusEnum.FAILED);
        }
        return result;
    }

    /**
     * 查询工单列表
     * @return
     */
    @Override
    public JsonBaseResult<Object> queryWorkOrderList() {
        JsonBaseResult<Object> result = new JsonBaseResult<>();
        List<WorkOrder> workOrderList = workOrderMapper.selectList(null);
        result.setResult(workOrderList);
        return result;
    }
}
